//==================================================================
/// CppKazRace_Paint.cpp
///
/// Created by Davide Pasca - 2010/4/1
/// See the file "license.txt" that comes with this project for
/// copyright info. 
//==================================================================

#include "stdafx.h"
#include "CppKazRace.h"

//==================================================================
void CppKazRace::lap_draw( graphics &g )
{
	long	laptime, min, sec, cent;
	int		mini_idx;
	long	mini;
	int		col1, col2;
	int		y;

	mpoFont->DrawText( g, g.mW-8, 4, 1, -1, 0xff5050, 0xa00000, 0x000000, "LAP:         " );


	mini = 2000000000;
	mini_idx = -1;
	for (int i=1; i < (int)_laptimes.size(); ++i)
	{
		laptime = _laptimes[i];
		if ( laptime != 0 )
			if ( laptime < mini )
			{
				mini = laptime;
				mini_idx = i;
			}
	}	

	y = 4;
	for (int i=0; i < (int)_laptimes.size(); ++i)
	{
		if ( i == mini_idx )
		{
			col1 = 0xff9090;
			col2 = 0x909090;
		}
		else
		{
			col1 = 0xffffff;
			col2 = 0x909090;
		}

		laptime = _laptimes[i];
		if ( laptime != 0 )
		{
			min = laptime / 1000 / 60;
			sec = (laptime - (min * 60 * 1000)) / 1000;
			cent = (laptime - ((min * 60 * 1000) + sec * 1000)) / 10;
			mpoFont->DrawText(
				g,
				g.mW-8,
				y,
				1,
				-1,
				col1,
				col2,
				0x000000,
				DUT::SSPrintFS( "      %i'%01i\".%01i", min, sec, cent ) );

			y += mpoFont->mCHe-2;
		}
	}
}

//==================================================================
void CppKazRace::mypaint()
{
	mpoHor->y_set( mpoRoad->y_get() );
	mpoHor->paint( *mpoOffGfx );
	if ( mpoRoad->paint( *mpoOffGfx ) )
	{
		lap_add_new();
		reset_pos();
	}

	mPlayerCar.Draw(
				*mpoOffGfx,
				*mpoXFormer,
				*mpoSmokeLPart,
				*mpoSmokeRPart,
				*mpoSmokeSprt,
				*mpoMyCarSptr,
				Vec3( mpoMyCarSptr->mX, mpoMyCarSptr->mY, mpoMyCarSptr->mZ )
			);
	//----------- TIME -------------
	lap_draw( *mpoOffGfx );

	//----------- STAGE -------------
	mpoFont->DrawText( *mpoOffGfx, mpoOffGfx->mW-8, mpoOffGfx->mH-6, 1, 1, 0xffff50, 0xa0a000, 0x000000, "STAGE  " );
	mpoFont->DrawText( *mpoOffGfx, mpoOffGfx->mW-8, mpoOffGfx->mH-6, 1, 1, 0xffffff, 0x909090, 0x000000, "      1" );
}

//==================================================================
